from django.db import models
from django.contrib.auth.models import User
from crm.models import Organisation, Client

class Venue(models.Model):
  """
  A venue is a place in which an event takes place
  """
  organisation = models.ForeignKey(Organisation, null=True, blank=True)
  def __unicode__(self):
    return self.organisation.name

class Location(models.Model):
  """
  A Location is a room within a venue in which a session takes place.
  """
  name = models.CharField(max_length=200)
  venue = models.ForeignKey(Venue)
  def __unicode__(self):
    return self.name

class EventType(models.Model):
  """
  There are a number of different event types such as workshops, online workshops, workshops, press conferences etc.
  """
  name = models.CharField(max_length=200)
  def __unicode__(self):
    return self.name  

class Event(models.Model):
  """
  An event is a complete set of sessions to which an attendee registers.
  """
  name = models.CharField(max_length=200)
  capacity = models.IntegerField()
  venue = models.ForeignKey(Venue)
  type = models.ForeignKey(EventType)
  def __unicode__(self):
    return self.name

class Track(models.Model):
  """
  A Track is a grouping of sessions, each event is made up of one or more tracks, each track runs at a single event.
  """
  name = models.CharField(max_length=200)
  description = models.TextField()
  event = models.ForeignKey(Event)
  def __unicode__(self):
    return self.name

class SessionType(models.Model):
  """
  A SessionType describes the types of sessions that we record. A session type is, for example, a
  tutoiral, a panel, a presentation etc.
  """
  name = models.CharField(max_length=200)
  def __unicode__(self):
    return self.name

class Participant(models.Model):
  """
  A participant is a person who is involved with a session in some formal way, they are not
  a member of the audience for a session.
  """
  person = models.ForeignKey(Client)
  def __unicode__(self):
    return self.person.user.first_name + " " + self.person.user.last_name

class Session(models.Model):
  """
  A session is a time delimeted period delivered by one or more people. There are different types of session, but
  they all capture essentially the same information: presenter(s), abstract, details, duration etc.
  """
  name = models.CharField(max_length=200)
  type = models.ForeignKey(SessionType)
  abstract = models.TextField()
  duration = models.IntegerField(help_text="Duration of the session in minutes")
  participant = models.ManyToManyField(Participant, help_text="Presenters, panelsits, chairs etc.")
  def __unicode__(self):
    return self.name

class Schedule(models.Model):
  """
  A schedule brings together a series of sessions into a track. There should be no more than one session sceduled at any
  one time in a track.
  """
  session = models.ForeignKey(Session)
  track = models.ForeignKey(Track)
  start_time = models.DateTimeField()
  def __unicode__(self):
    return self.session.name

class Sponsor(models.Model):
  """
  A Sponsor is an organisation that provides some form of support for an event
  """
  event = models.ForeignKey(Event)
  organisation = models.ForeignKey(Organisation)
  def __unicode__(self):
    return self.organisation.name

  
